import useDictStore from '@/store/dict';
import { getDictList } from '@/api/system/dict'
import { ref, toRefs } from 'vue';

const dictStore = useDictStore();

function useDict(...args){
    const res = ref({});
    args.forEach((dictType) => {
        res.value[dictType] = [];
        const dict = dictStore.getDict(dictType);
        if(dict){
            res.value[dictType] = dict;
        }else{
            getDictList(dictType).then((dictList) => {
                res.value[dictType] = dictList;
                dictStore.setDict(dictType, dictList);
            })
        }
    })
    return toRefs(res.value);
}
export default useDict;


